package com.mrx.commons.exception;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.filter.ExceptionFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Mr.X
 * @since 2023-02-19 15:31
 */
@Activate(group = CommonConstants.PROVIDER)
public class XExceptionFilter extends ExceptionFilter {

    private static final Logger logger = LoggerFactory.getLogger(XExceptionFilter.class);

    public XExceptionFilter() {
        logger.debug("构造自定义 dubboExceptionFilter");
    }

    @Override
    public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
        Throwable exception = appResponse.getException();
        if (exception instanceof BusinessException) {
            return;
        }
        super.onResponse(appResponse, invoker, invocation);
    }

}
